package myTest;

import java.io.FileInputStream;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;

import org.junit.Test;

public class MyNioTest {

	@Test
	public void testReadByNio() throws Exception{
		FileInputStream fin = new FileInputStream("d:\\mysql.log");  
        
        // 获取通道  
        FileChannel fc = fin.getChannel();  
          
        // 创建缓冲区  
        ByteBuffer buffer = ByteBuffer.allocate(1024);  
        while(true){
        	buffer.clear();
        	if(fc.read(buffer)<0){
        		break;
        	};
        	buffer.flip();  
            
            while (buffer.remaining()>0) {  
                byte b = buffer.get();  
                System.out.print(((char)b));  
            }  
        }
          
        fin.close();  
	}
}
